package org.example.mall.admin.configuration.auth.code;

import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.example.mall.admin.constant.auth.AuthTypeConst;
import org.example.mall.admin.constant.CommonConstants;
import org.example.mall.admin.util.R;
import org.example.mall.admin.configuration.SpringContextHolder;
import org.springframework.stereotype.Component;

/**
 * @author hzq
 * @date 2022/1/3 11:16
 */
@Slf4j
@Component
public class ImageSendCodeHandler extends AbstractSendCodeHandler {

    @Override
    public R<Object> sendCode(String scenes, String principal, String handlerType) {
        CaptchaVO vo = new CaptchaVO();
        vo.setCaptchaType(CommonConstants.IMAGE_CODE_TYPE);
        CaptchaService captchaService = SpringContextHolder.getBean(CaptchaService.class);
        ResponseModel responseModel = captchaService.get(vo);
        return R.ofSuccess(responseModel);
    }

    @Override
    protected boolean supportType(String handlerType) {
        return AuthTypeConst.IMAGE.equals(handlerType);
    }

    @Override
    protected boolean supportScenes(String scenes) {
        return ScenesConst.LOGIN.equals(scenes);
    }

    @Override
    protected R<Object> handler(String scenes, String principal, String handlerType) {
        return null;
    }
}
